#!/bin/env bash

cat /etc/issue | grep -i ubuntu >/dev/null 2>&1
if [[ "$?"x != "0x" ]]; then
    echo "only support ubuntu distribution"
    exit 1
fi


echo "Notice: lcov_helper will require administor password for install dependencies and modify config."
echo -e "DO NOT PANIC, it is safe!\n"

command -v lcov >/dev/null 2>&1
if [[ "$?"x != "0x" ]]; then
    echo "lcov not install, install it..."
    sudo apt-get install lcov
else
    echo "lcov already install, skip installation"
fi

echo "start modify lcov config to enable branch coverage..."
sudo sed -i '/.*lcov_branch_coverage*/c\lcov_branch_coverage = 1' /etc/lcovrc
sudo sed -i '/.*genhtml_branch_coverage*/c\genhtml_branch_coverage = 1' /etc/lcovrc

echo "lcov_helper finish all task."
